package cn.itsource.controller;

import cn.itsource.domain.Emp;
import cn.itsource.service.IEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
@Controller
@RequestMapping("/emp")
public class Empcontroller {
    //在controller层中调用service对象中的服务,在service对象中调用mapper层对象,再向mybatis底层配置文件中配置web信息
    @Autowired
    IEmpService service;
    @RequestMapping("/list")
    @ResponseBody
    public List<Emp> findAll(){
            List<Emp> list=service.findAll();
            return list;
    }
    @RequestMapping("/del")
    @ResponseBody
    public String delById(Integer eid){
        try {
            service.delById(eid);
            return "ok";
        }catch (Exception e){
            return "error";
        }
    }
    @RequestMapping("/save")
    @ResponseBody
    public String save(Emp emp){
        try{
            System.err.println(emp);
            service.save(emp);
            return "ok";
        }catch (Exception e){
            return "error";
        }
    }
}
